package com.sunshine.common.entity;

import com.sunshine.common.enums.ResultCodeEnum;
import lombok.Data;

/**
 * @Description: 统一返回结果
 * @version 1.0
 * @Author 夏百友
 * @Date 2025/11/2 16:39
 */

@Data
public class Result<T> {


    private Boolean success;
    private String message;
    private Integer code;
    private T data;


    public static Result ok() {
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCodeEnum.Success.getCode());
        result.setMessage(ResultCodeEnum.Success.getDesc());
        return result;
    }

    public static<T> Result ok(T  data) {
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCodeEnum.Success.getCode());
        result.setMessage(ResultCodeEnum.Success.getDesc());
        result.setData(data);
        return result;
    }
    
    public static Result fail() {
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(ResultCodeEnum.Fail.getCode());
        result.setMessage(ResultCodeEnum.Fail.getDesc());
        return result;
    }

    public static Result fail(String message) {
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(ResultCodeEnum.Fail.getCode());
        result.setMessage(message);
        return result;
    }


}